Typedict
TypedDict describe a structured dictionary/map where the ,
type of each dictionary value depends on the key,
It’s allow mypy and the VSCode to help enforce dictionary structure
from typing import TypedDict
class Movie(TypedDict):
name: str
year: int
movie: Movie = {"name": "toy", "year": 1900}
print(type(movie))
d = dict(movie)
print(type(d))
#

total#
from typing import TypedDict
class Movie(TypedDict):
name: str
year: int
movie: Movie = {"name": "toy"}
mypy output
mypy <file to check.py>
...
error: Missing key "year" for TypedDict "Movie"
from typing import TypedDict
class Movie(TypedDict, total=False):
name: str
year: int
movie: Movie = {"name": "toy"}
mypy output
mypy <file to check.py>
Success: no issues found in 1 source file